package com.sinux.generality.provider.demo.thread;

import com.sinux.generality.provider.demo.constants.Sets;
import com.sinux.generality.provider.demo.entity.Optionlog;
import com.sinux.generality.provider.demo.service.OptionlogService;
import com.sinux.generality.provider.demo.tool.SpringContextUtil;

public class OptionThread implements Runnable{
    private OptionlogService ols;
    public OptionThread(OptionlogService ols){
        if(ols == null){
            ols = SpringContextUtil.getBean(OptionlogService.class);
        }
        this.ols = ols;
    }
    @Override
    public void run() {

        while(true) {
            try {
                // 线程入日志
                Optionlog ol = Sets.optionQueue.take();
                ols.save(ol);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
